package com;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class TrialBalanceServlet2
 */
@WebServlet("/TrialBalanceServlet2")
public class TrialBalanceServlet2 extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static final String forwardTo 
	= "/servlet/com." +
	"CustomerLedgerPeriodicServlet";
    /**
     * @see HttpServlet#HttpServlet()
     */
    public TrialBalanceServlet2() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		String value1=request.getParameter("name");
		System.out.println("Account name-"+value1);
		
		String value2=request.getParameter("code");
		System.out.println("Account code-"+value2);
		
		String value3=request.getParameter("group");
		System.out.println("Account group-"+value3);
		
		//String amit=request.getParameter("customerledgerreport");
		//System.out.println(amit);
		
		 if(value3.equals("Sundry Debtors"))
		{
			request.setAttribute("accountname",value1);
			request.setAttribute("accountcode",value2);
			request.setAttribute("accountgroup",value3);
	        RequestDispatcher requestDispatcher; 
	        requestDispatcher = request.getRequestDispatcher("CustomerLedgerReport.jsp" ) ;
	        requestDispatcher.forward(request,response);
		}
		else if(value3.equals("Sundry Creditors"))
		{
			request.setAttribute("accountname",value1);
			request.setAttribute("accountcode",value2);
			request.setAttribute("accountgroup",value3);
			RequestDispatcher requestDispatcher; 
			requestDispatcher = request.getRequestDispatcher("SupplierLedgerReport.jsp" ) ;
			requestDispatcher.forward(request,response);
		}
		else
		{
			request.setAttribute("accountname",value1);
			request.setAttribute("accountcode",value2);
			request.setAttribute("accountgroup",value3);
			RequestDispatcher requestDispatcher; 
			requestDispatcher = request.getRequestDispatcher("GeneralLedgerReport.jsp" ) ;
			requestDispatcher.forward(request,response);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String mode = request.getParameter("customerledgerreoprt");

	System.out.println("hihi");
		if(mode != null && mode.equals("forward")) {
			request.setAttribute("mode", "Forwarding Response..");
		  request.getRequestDispatcher(forwardTo).forward(request, response);
		}
		
	}

}
